#include"comm.hpp"

// int main()
// { 
  
//   int shmid = CreateShm();
//   _log(Debug,"create shm done!");
//   sleep(3);
//   char* shmaddr = (char*)shmat(shmid,nullptr,0);
//   //关联
//   _log(Debug,"attach shm done!,shnaddr: 0x%x",shmaddr);
 
//   sleep(3);
//   shmdt(shmaddr);//去关联
//   _log(Debug,"detach shm done,shmaddr:0x%x",shmaddr);

//   sleep(3);
//   shmctl(shmid,IPC_RMID,nullptr);//释放空间
//   _log(Debug,"rm ID success");
//   return 0;
// }


int main()
{ 
  
  int shmid = CreateShm();
  char* shmaddr = (char*)shmat(shmid,nullptr,0);
  _log(Debug,"attach shm done!,shnaddr: 0x%x",shmaddr);

  //ipc code
  const string str = "fuck you b";
  //一旦有人把输入写入到共享内存,立马就能看到了！！
  //不需要经过系统调用,直接就能看到数据了

  struct shmid_ds shmds;
  while(1)
  {
    cout << "client say@" << shmaddr << endl;
    //直接访问
    sleep(1);

    shmctl(shmid,IPC_STAT,&shmds);
     //shmds来获取共享内存属性。 
  }


  shmdt(shmaddr);//去关联
  shmctl(shmid,IPC_RMID,nullptr);//释放空间
  return 0;
}